home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / xvisrc.zip / 8086MM.INC next >
Text File  |  1992-07-28  |  2KB  |  135 lines

  1. ; Copyright (c) 1990,1991,1992 Chris and John Downey
  2. ;***
  3. ;
  4. ; program name:
  5. ;    xvi
  6. ; function:
  7. ;    PD version of UNIX "vi" editor, with extensions.
  8. ; module name:
  9. ;    8086mm.inc
  10. ; module function:
  11. ;    8086 assembly language macros, mainly to help make assembly
  12. ;    language modules memory model independent.
  13. ;
  14. ;    This isn't really needed for Xvi (which uses the large memory
  15. ;    model), but if we want to provide a portable terminal
  16. ;    interface library which can also be used by other
  17. ;    applications, it will almost certainly be needed.
  18. ; history:
  19. ;    STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  20. ;    Originally by Tim Thompson (twitch!tjt)
  21. ;    Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  22. ;    Heavily modified by Chris & John Downey
  23. ;***
  24.  
  25. ;
  26. ; Memory model definitions.
  27. ;
  28. s    equ    0
  29. m    equ    1
  30. c    equ    2
  31. l    equ    3
  32.  
  33. ;
  34. ; Define sizes of code & data pointers.
  35. ;
  36. if MEMMODEL eq s
  37.     CPTRSIZE    =    2
  38.     DPTRSIZE    =    2
  39. endif
  40.  
  41. if MEMMODEL eq m
  42.     CPTRSIZE    =    4
  43.     DPTRSIZE    =    2
  44. endif
  45.  
  46. if MEMMODEL eq c
  47.     CPTRSIZE    =    2
  48.     DPTRSIZE    =    4
  49. endif
  50.  
  51. if MEMMODEL eq l
  52.     CPTRSIZE    =    4
  53.     DPTRSIZE    =    4
  54. endif
  55.  
  56. ;
  57. ; Useful macros defined according to the memory model.
  58. ;
  59.  
  60. ;
  61. ; Declare an external function written in C.
  62. ;
  63. C_extern    macro    funcname
  64.     if CPTRSIZE eq 4
  65.         extrn    funcname : far
  66.     else
  67.         extrn    funcname : near
  68.     endif
  69.         endm
  70.  
  71. ;
  72. ; Return to C caller.
  73. ;
  74. C_ret        macro
  75.     if CPTRSIZE eq 4
  76.         retf
  77.     else
  78.         db    0c3h    ;; Near return.
  79.     endif
  80.         endm
  81.  
  82. ;
  83. ; Call another routine which returns with a C_ret & is in the same
  84. ; segment as the caller.
  85. ;
  86. Cn_call        macro    func
  87.     if CPTRSIZE eq 4
  88.         push    cs
  89.     endif
  90.         call    func
  91.         endm
  92.  
  93. ;
  94. ; Assign a one-word value by dereferencing a pointer.
  95. ;
  96. ; In C, this would be:
  97. ;
  98. ;    *memptr = value;
  99. ;
  100. ; Note that:
  101. ;
  102. ;    - bx is destroyed. For compact & large memory models, ds is
  103. ;      also destroyed.
  104. ;
  105. ;    - for small & medium memory models, memptr is a near pointer,
  106. ;      which must be relative to ds.
  107. ;
  108. ptrasg        macro    memptr, value
  109.     if DPTRSIZE eq 4
  110.         lds    bx, dword ptr memptr
  111.         assume    ds: nothing
  112.     else
  113.         mov    bx, memptr
  114.     endif
  115.         mov    [bx], value
  116.         endm
  117.  
  118. ;
  119. ; Generally useful macros, defined here for convenience.
  120. ;
  121.  
  122. ;
  123. ; Clear a register to 0.
  124. ;
  125. clear        macro    reg
  126.         xor    reg, reg
  127.         endm
  128.  
  129. ;
  130. ; Test a register for equality with 0.
  131. ;
  132. tst        macro    reg
  133.         or    reg, reg
  134.         endm
  135.